package cn.topevery.garden.wapi.controller;

import hw.topevery.fmp.runtime.FmpRuntime;
import hw.topevery.framework.DataResult;
import hw.topevery.framework.omi.RsResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/fmp")
@RestController
public class FileController extends BaseController {

    @PostMapping("/uploadFile")
    public DataResult<String> uploadFile(MultipartFile file) throws Exception {
        DataResult<String> res = new DataResult<>();

        RsResult rsResult = FmpRuntime.upload(file);
        res.data = rsResult.dataJsonVal;
        res.success = rsResult.success;
        return res;
    }
    @GetMapping("/file")
    public void getFile(String fileId) throws Exception {
        FmpRuntime.download(fileId);
    }

    @GetMapping("/thumbnail")
    public void getThumbnailFile(String fileId, Integer w, Integer h) throws Exception {
        FmpRuntime.download(fileId, w, h);
    }
}
